package com.px.auditRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.px.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.enums.BusinessType;
import com.px.auditRecord.domain.AuditRecordUser;
import com.px.auditRecord.service.IAuditRecordUserService;
import com.px.common.utils.poi.ExcelUtil;
import com.px.common.core.page.TableDataInfo;

/**
 * 备案人员审核Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("备案人员审核")
@RestController
@RequestMapping("/auditRecord/user")
public class AuditRecordUserController extends BaseController
{
    @Autowired
    private IAuditRecordUserService auditRecordUserService;

    /**
     * 查询备案人员审核列表
     */
    @ApiOperation("查询备案人员审核列表")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(AuditRecordUser auditRecordUser)
    {
        startPage();
        List<AuditRecordUser> list = auditRecordUserService.selectAuditRecordUserList(auditRecordUser);
        return getDataTable(list);
    }

    /**
     * 导出备案人员审核列表
     */
    @ApiOperation("导出备案人员审核列表")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:query')")
    @Log(title = "备案人员审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter(outEncode = false)
    public void export(HttpServletResponse response, AuditRecordUser auditRecordUser)
    {
        List<AuditRecordUser> list = auditRecordUserService.selectAuditRecordUserList(auditRecordUser);
        ExcelUtil<AuditRecordUser> util = new ExcelUtil<AuditRecordUser>(AuditRecordUser.class);
        util.exportExcel(response, list, "备案人员审核数据");
    }


    /**
     * 获取备案人员审核详细信息
     */
    @ApiOperation("获取备案人员审核详细信息")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:query')")
    @GetMapping(value = "/userId/{userId}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return success(auditRecordUserService.selectAuditRecordUserByUserId(userId));
    }

    /**
     * 获取备案人员审核详细信息
     */
    @ApiOperation("获取备案人员审核详细信息")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:query')")
    @GetMapping(value = "/idcard/{idcard}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("idcard") String idcard)
    {
        return success(auditRecordUserService.selectAuditRecordUserByIdcardAll(idcard));
    }

    /**
     * 新增备案人员审核
     */
    @ApiOperation("新增备案人员审核")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:edit')")
    @Log(title = "备案人员审核", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody AuditRecordUser auditRecordUser)
    {
        auditRecordUser.setCreateBy(getUsername());
        auditRecordUser.setCreateTime(DateUtils.getNowDate());
        return toAjax(auditRecordUserService.insertAuditRecordUser(auditRecordUser));
    }

    /**
     * 修改备案人员审核
     */
    @ApiOperation("修改备案人员审核")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:edit')")
    @Log(title = "备案人员审核", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody AuditRecordUser auditRecordUser)
    {
        auditRecordUser.setUpdateBy(getUsername());
        auditRecordUser.setUpdateTime(DateUtils.getNowDate());
        return toAjax(auditRecordUserService.updateAuditRecordUser(auditRecordUser));
    }

    /**
     * 删除备案人员审核
     */
    @ApiOperation("删除备案人员审核")
    @PreAuthorize("@ss.hasPermi('auditRecord:user:remove')")
    @Log(title = "备案人员审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(auditRecordUserService.deleteAuditRecordUserByIds(ids));
    }

    /**
     * 新增备案人员审核
     */
    @PostMapping("/flightAdd")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult flightAdd(@RequestBody AuditRecordUser auditRecordUser)
    {
        auditRecordUser.setCreateBy(getUsername());
        auditRecordUser.setCreateTime(DateUtils.getNowDate());

        return toAjax(auditRecordUserService.insertAuditRecordUser(auditRecordUser));
    }


    @ApiOperation("个人查询备案人员审核列表")
    @GetMapping("/flightList")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo FlightList(AuditRecordUser auditRecordUser)
    {
        startPage();
        auditRecordUser.setId(getUserId().intValue());
        List<AuditRecordUser> list = auditRecordUserService.selectAuditRecordUserFlightList(auditRecordUser);
        return getDataTable(list);
    }


}
